import { MapPoint } from '../pouch/models/City';

export function getCenter(xs: MapPoint[]): MapPoint {
	let left = 180, right = -180, top = 0, bottom = 90;
	xs.forEach(x => {
		if (x.lng < left) {
			left = x.lng;
		}

		if (x.lng > right) {
			right = x.lng;
		}

		if (x.lat > top) {
			top = x.lat;
		}

		if (x.lat < bottom) {
			bottom = x.lat;
		}
	});

	return {
		lng: (left + right) / 2,
		lat: (top + bottom) / 2
	};
}
